<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table2">
<div class="content-table-title"><?=$this->title?></div>
<br />
<?php if($this->msg):?>
<div class="replace"><?=$this->msg?></div>
<br />
<?php endif;?>
<div class="form-edit-task">

<form action="/clients/edit-client-submit" method="post" name="form1" onsubmit="submitform(this);return false;">
<table border="0" width="100%">
	<tr>
		<td align="right" width="30%">客户全称：</td>
		<td align="left">&nbsp;<input type="text" placeholder="客户全称" name="client_name" id="client_name" value="<?=$this->data['client_name']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">省份：</td>
		<td align="left"><select name="provinceId" id="provinceId" onchange="GetCities(this.options[this.options.selectedIndex].value);">
					<option value="">不限</option>
					<?php if(!empty($this->provinces)):?>
					<?php foreach($this->provinces as $provinceId => $provinceName):?>
					<option value="<?=$provinceId?>" <?php if($provinceId==$this->data['province_id']){echo "selected='selected'";}?>><?=$provinceName?></option>
					<?php endforeach;?>
					<?php endif;?>
				</select><font color="red"> *</font>
		</td>
	</tr>
	<tr>
		<td align="right">城市：</td>
		<td align="left"><select name="cityId" id="cityId" onchange="GetCounties(this.options[this.options.selectedIndex].value);">
			<?php if($this->init_cities):?>
				<?php foreach($this->init_cities as $cities):?>
				<option value="<?=$cities['cityId']?>" <?php if($cities['cityId']==$this->data['city_id']){echo "selected='selected'";}?>><?=$cities['cityName']?></option>
				<?php endforeach;?>
			<?php endif;?>
			</select><font color="red"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">区/县：</td>
		<td align="left"><select name="countyId" id="countyId">
			<?php if($this->init_counties):?>
				<?php foreach($this->init_counties as $counties):?>
				<option value="<?=$counties['countyId']?>" <?php if($counties['countyId']==$this->data['county_id']){echo "selected='selected'";}?>><?=$counties['countyName']?></option>
				<?php endforeach;?>
			<?php endif;?>
			</select><font color="red"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">联系地址：</td>
		<td align="left">&nbsp;<input type="text" placeholder="地址" name="address" id="address" value="<?=$this->data['address']?>" style="width: 400px"></td>
	</tr>
	<tr>
		<td align="right">邮编：</td>
		<td align="left">&nbsp;<input type="text" placeholder="邮编" name="zipcode" id="zipcode" value="<?=$this->data['zipcode']?>"></td>
	</tr>
	<tr>
		<td align="right">电话：</td>
		<td align="left">&nbsp;<input type="text" placeholder="电话" name="tel" id="tel" value="<?=$this->data['tel']?>"></td>
	</tr>
	<tr>
		<td align="right">手机：</td>
		<td align="left">&nbsp;<input type="text" placeholder="手机" name="cellphone" id="cellphone" value="<?=$this->data['cellphone']?>"></td>
	</tr>
	<tr>
		<td align="right">传真：</td>
		<td align="left">&nbsp;<input type="text" placeholder="传真" name="fax" id="fax" value="<?=$this->data['fax']?>"></td>
	</tr>
	<tr>
		<td align="right">类型：</td>
		<td align="left"><select name="client_type_id" id="client_type_id">
				<option value=""></option>
				<?php foreach($this->client_types as $client_type_id => $type_name):?>
				<option value="<?=$client_type_id?>" <?php if($client_type_id==$this->data['client_type_id']){echo "selected='selected'";}?>><?=$type_name?></option>
				<?php endforeach;?>
		</select><font color="red"><font color="red"> *</font>
		<input type="hidden" name="is_nobody" value="<?=$this->data['client_type_id']?"0":"1"?>" />
		</td>
	</tr>
	<?php if("LEVEL-3" == $_SESSION['identity']['level']): //合同管理员可以更改is_dealer?>
	
	<?php if(!empty($this->dealers_in_same_name)):?>
	<tr>
		<td align="right">经销商ID：</td>
		<td align="left">
			<?php foreach($this->dealers_in_same_name as $dealers_in_same_name):?>
			
			<?php if(!empty($dealers_in_same_name['brands'])):?>
			<?php $brand_txt = " - (".implode(", ", $dealers_in_same_name['brands']).")";?>
			<?php else:?>
			<?php $brand_txt = "";?>
			<?php endif;?>
			
			<input type="radio" name="is_dealer" id="is_dealer_<?=$dealers_in_same_name['dealer_id']?>" value="<?=$dealers_in_same_name['dealer_id']?>" <?php if($dealers_in_same_name['dealer_id']==$this->data['is_dealer']):?>checked="checked"<?php endif;?> /> <label for="is_dealer_<?=$dealers_in_same_name['dealer_id']?>"><?=$dealers_in_same_name['dealer_id']?> - <?=$dealers_in_same_name['company_name']?><?=$brand_txt?>
				<br />&nbsp;&nbsp;&nbsp;&nbsp;<?=$dealers_in_same_name['address']?></label>
				<br />
			<?php endforeach;?>
		</td>
	</tr>
	<?php endif;?>
	
	<?php else: //其他人只能看?>
	
	<?php if($this->data['is_dealer']):?>
	<tr>
		<td align="right">经销商ID：</td>
		<td align="left">&nbsp;<?=$this->data['is_dealer']?></td>
	</tr>
	
	<?php endif;?>
	<?php endif;?>
	<tr>
		<td align="right">所属销售顾问：</td>
		<td align="left">
			<?php if("LEVEL-1" == $_SESSION['identity']['level']):?>
			<?php if($this->data['emp_id']):?>
			<select name="emp_id" id="emp_id" disabled="disabled">
			<?php foreach($this->sales as $emp_id => $name):?>
				<option value="<?=$emp_id?>" <?php if($emp_id==$this->data['emp_id']){echo "selected='selected'";}?>><?=$name?></option>
			<?php endforeach;?>
			</select>
			<?php else:?>
			<select name="emp_id" id="emp_id">
				<option value="" selected="selected">【不认领】</option>
				<option value="<?=$_SESSION['identity']['userid']?>">【认领为我的客户】</option>
			</select>
			<?php endif;?>
			<?php elseif(in_array($_SESSION['identity']['level'], array("LEVEL-2", "LEVEL-3"))):?>
			<select name="emp_id" id="emp_id">
			<?php foreach($this->sales as $emp_id => $name):?>
				<option value="<?=$emp_id?>" <?php if($emp_id==$this->data['emp_id']){echo "selected='selected'";}?>><?=$name?></option>
			<?php endforeach;?>
			</select>
			<?php else:?>
			<select name="emp_id" id="emp_id" disabled="disabled">
			<?php foreach($this->sales as $emp_id => $name):?>
				<option value="<?=$emp_id?>" <?php if($emp_id==$this->data['emp_id']){echo "selected='selected'";}?>><?=$name?></option>
			<?php endforeach;?>
			</select>
			<?php endif;?>
		</td>
	</tr>
	<tr>
		<td align="right">签约公司：</td>
		<td align="left">
			-------------------------------------<br />
			<?php if($this->been_signers):?>
			<?php $n = 1;?>
			<?php foreach($this->been_signers as $been_signers):?>
			<?=$n.". ".$been_signers['company_name']?>【<?php if(1==$been_signers["status"]){echo "<font color='green'>已通过</font>";}elseif(2==$been_signers["status"]){echo "<font color='red'>已驳回</font>";}else{echo "待审核";}?>】&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="删除" onclick='javascript:return del(<?=$been_signers['row_id']?>)'><br>
			<?php $n += 1;?>
			<?php endforeach;?>
			<?php endif;?>
			<select name="signer_id" id="signer_id">
				<option value="">【无操作】</option>
				<option value="create">【申请为签约公司】</option>
				<?php if($this->signers):?>
				<?php foreach($this->signers as $signer_id => $signer_name):?>
				<option value="<?=$signer_id?>"><?=$signer_name?></option>
				<?php endforeach;?>
				<?php endif;?>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="hidden" name="client_id" value="<?=$this->data['client_id']?>" /><input type="button" class="buttonlong" value="提交" onclick="submitform();return false;" /></td>
	</tr>
</table>
<br /><br />
</form>
</div>
<br/><br/>
</div>

<script>
function del(row_id) { 
	var msg = "确定要删除吗？"; 
	if (confirm(msg)==true){ 
		window.location.href='/clients/del-signer/row_id/' + row_id + "/client_id/<?=$this->data['client_id']?>";
	}else{ 
		return false; 
	} 
}

function GetCities(provinceId)
{
	$.ajax({
			type: "post",
			url : "/ajax/get-cities",
			dataType:'json',
            async:false,
			data: {
					'provinceId':provinceId
				  },
				success: function(json){
					if(json.result == 1 && typeof(json.data) != "undefined") {
                        var arr = json.data;
						var txt = "<option value=''>不限</option>";
						
                        for(i=0; i < arr.length; i++){
							txt += "<option value='" + arr[i]['cityId'] + "'>" + arr[i]['cityName'] + "</option>";
                        }
						
						document.getElementById("cityId").innerHTML = txt;
                    }
			}
		});
}

function GetCounties(cityId)
{
	$.ajax({
			type: "post",
			url : "/ajax/get-counties",
			dataType:'json',
            async:false,
			data: {
					'cityId':cityId
				  },
				success: function(json){
					if(json.result == 1 && typeof(json.data) != "undefined") {
                        var arr = json.data;
						var txt = "<option value=''>不限</option>";
						
                        for(i=0; i < arr.length; i++){
							txt += "<option value='" + arr[i]['countyId'] + "'>" + arr[i]['countyName'] + "</option>";
                        }
						
						document.getElementById("countyId").innerHTML = txt;
                    }
			}
		});
}

function submitform() 
{
	
	if( document.form1.client_name.value.length == 0 )
	{
		alert("客户全称不能为空。");
		return false;
	}else if( document.form1.provinceId.value.length == 0 )
	{
		alert("省份不能为空。");
		return false;
	}else if( document.form1.cityId.value.length == 0 )
	{
		alert("城市不能为空。");
		return false;
	}else if( document.form1.client_type_id.value.length == 0 )
	{
		alert("类型不能为空。");
		return false;
	}
	
	form1.submit();
}
</script>
